package com.efast.dmom.mgmt.service.mes.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.servlet.http.HttpServletResponse;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.cafe.portal.entity.base.PortalBaseLov;
import com.efast.cafe.portal.remote.base.PortalBaseLovService;
import com.efast.dmom.mgmt.dao.mes.PmFeaturValueDao;
import com.efast.dmom.mgmt.dao.mes.PmPartModelAndVinRuleDao;
import com.efast.dmom.mgmt.dao.mes.PmSerialnumberDao;
import com.efast.dmom.mgmt.dao.mes.PrBasLoadingListDao;
import com.efast.dmom.mgmt.dao.mes.TwBasLotDao;
import com.efast.dmom.mgmt.entity.mes.PmFeaturValue;
import com.efast.dmom.mgmt.entity.mes.PmPartModelAndVinRule;
import com.efast.dmom.mgmt.entity.mes.PmSerialnumber;
import com.efast.dmom.mgmt.entity.mes.PrBasLoadingList;
import com.efast.dmom.mgmt.entity.mes.TwBasLot;
import com.efast.dmom.mgmt.service.mes.PrBasLoadingListService;
import com.efast.dmom.mgmt.utils.PrintCardUtil;


@Service
public class PrBasLoadingListServiceImpl implements PrBasLoadingListService {
	@Autowired
	private PrBasLoadingListDao listDao;
	@Autowired
	private TwBasLotDao lotDao;
	@Autowired
	private PortalBaseLovService pbsi;
	@Autowired
	private PmFeaturValueDao pmFeaturValueDao;
	@Autowired
	private PmSerialnumberDao pmSerialnumberDao;
	@Autowired
	private PmPartModelAndVinRuleDao vinRuleDao;

	// vin号，配置类型（主线装车单），打印函数
	@Override
	public ResultBean printLoadingList(PrBasLoadingList enti) throws Exception {

		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		Map<String, Object> parameters = new HashMap<String, Object>();

		// 获取打印机名称
		String printName = enti.getPrintName();
		String vin = enti.getVin();
		String printType = enti.getPrintType();
		String templateName = enti.getTemplateName();
		Boolean printStatus = enti.getPrintStatus();
		parameters.put("vin", vin);
		parameters.put("printType", printType);
		parameters.put("templateName", templateName);
		parameters.put("printUser", SpringWebUtils.getRequestUser());
		parameters.put("printName", printName);
	
		// 将map转成json格式
		String jsonString = JSONObject.toJSONString(parameters);
		// 获取配置的打印服务的URL
		List<PortalBaseLov> lists = pbsi.api_queryListByParamKey1("PrintUrl");
		if (lists == null || lists.size() < 1) {
			result.setSuccess(false);
			result.setMessage("无法获取打印服务的URL");
			return result;
		}
		String printUrl = lists.get(0).getOption_key();

		JaxWsDynamicClientFactory dcflient = JaxWsDynamicClientFactory.newInstance();
		// 连接打印服务
		try {
			Client client = dcflient.createClient(printUrl);
			if(printStatus) {
				Object[] results=client.invoke("printLoadingList", jsonString);
				if(results[0]!=null) {
					result.setSuccess(false);
					result.setMessage((String) results[0]);
					return result;	
				}
			}else {
				Object[] results=client.invoke("printLoadingListAgain", jsonString);
				if(results[0]!=null) {
					result.setSuccess(false);
					result.setMessage((String) results[0]);
					return result;	
				}	
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			result.setSuccess(false);
			result.setMessage("连接打印服务接口失败！");
			return result;
		}
		return result;
	}
	@Override
	public ResultBean printCabList(PrBasLoadingList enti) {

	ResultBean result = new ResultBean(true, "'");
	result.setSuccess(true);
	Map<String, Object> parameters = new HashMap<String, Object>();

	// 获取打印机名称
	String printName = enti.getPrintName();
    String vin = enti.getVin();
    String printType = enti.getPrintType();
    String templateName = enti.getTemplateName();
    Boolean printStatus = enti.getPrintStatus();
	parameters.put("bsn", vin);
	parameters.put("printType", printType);
	parameters.put("templateName", templateName);
	parameters.put("printUser", SpringWebUtils.getRequestUser());
	parameters.put("printName", printName);
	// 将map转成json格式
	String jsonString = JSONObject.toJSONString(parameters);
	// 获取配置的打印服务的URL
	List<PortalBaseLov> lists = pbsi.api_queryListByParamKey1("PrintUrl");
	if (lists == null || lists.size() < 1) {
		result.setSuccess(false);
		result.setMessage("无法获取打印服务的URL");
		return result;
	}
	String printUrl = lists.get(0).getOption_key();

	JaxWsDynamicClientFactory dcflient = JaxWsDynamicClientFactory.newInstance();
	// 连接打印服务
	try {
		Client client = dcflient.createClient(printUrl);
		if(printStatus) {
			Object[] results=client.invoke("printCabList", jsonString);
			if(results[0]!=null) {
				result.setSuccess(false);
				result.setMessage((String) results[0]);
				return result;	
			}
		}else {
			Object[] results=client.invoke("printCabListAgain", jsonString);
			if(results[0]!=null) {
				result.setSuccess(false);
				result.setMessage((String) results[0]);
				return result;	
			}	
		}

	} catch (Exception e) {
		// TODO Auto-generated catch block
		result.setSuccess(false);
		result.setMessage("连接打印服务接口失败！");
		return result;
	}
	return result;
	}
	@Override
	public PrintService getPrintService(String printName) {
		// TODO Auto-generated method stub

		PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

		DocFlavor flavor = DocFlavor.BYTE_ARRAY.PNG;
		// 可用的打印机列表(字符串数组)
		PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);

		if (printService != null) {
			for (PrintService p : printService) {
				System.out.println("printname=" + p.getName());
				if (p.getName().equals(printName)) {

					return p;
				}
			}
		}
		return null;

	}

	// 连接打印服务进行打印
	@Override
	public String getService(String json) {
		// 获取配置的打印服务的URL
		List<PortalBaseLov> list = pbsi.api_queryListByParamKey1("PrintUrl");
		if (list == null || list.size() < 1) {
			return "无法获取打印服务的URL";
		}
		String printUrl = list.get(0).getOption_key();

		JaxWsDynamicClientFactory dcflient = JaxWsDynamicClientFactory.newInstance();
		// 连接打印服务

		// 调打印接口
		try {
			Client client = dcflient.createClient(printUrl);
			client.invoke("printLoadingList", json);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return "连接打印服务接口失败！";
		}

		return "";

	}

	@Override
	public ResultBean getVehicleModelColor(String vin) {
		// TODO Auto-generated method stub
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		
		List<TwBasLot> list = lotDao.selectTwBasLotByVin(vin);
		if (list == null || list.size()<1) {
			result.setSuccess(false);
			result.setMessage("无法获取车辆信息");
			return result;
		}
		TwBasLot basLot = list.get(0) ;
		String partNoVersion = basLot.getPartNoVersion();

		if (partNoVersion == null || "".equals(partNoVersion)) {
			result.setSuccess(false);
			result.setMessage("无法获取物料号信息");
			return result;
		}
		String paintColorNum = partNoVersion.substring(partNoVersion.length() - 9, partNoVersion.length() - 8);
		String colorNum = partNoVersion.substring(partNoVersion.length() - 8, partNoVersion.length() - 6);
		String model = "";
		String paintColor = "";
		String color = "";
		Map<String, Object> parameters = new HashMap<String, Object>();
		List<PmPartModelAndVinRule> listVinRuleInfo = vinRuleDao.getVinRuleInfo(partNoVersion);
		if(listVinRuleInfo==null || listVinRuleInfo.size()<1 ) {
			result.setSuccess(false);
			result.setMessage("无法获取车型配置信息");
			return result;
		}
		model = listVinRuleInfo.get(0).getModel();
		// 获取车漆配置信息
		List<PmFeaturValue> paintColorNumList = pmFeaturValueDao.getFeaturValueByType("vehiclePaintType",
				paintColorNum);
		if (paintColorNumList.size() < 1) {
			result.setSuccess(false);
			result.setMessage("无法获取车漆属性配置信息");
			return result;
		}
		paintColor = paintColorNumList.get(0).getFeatueValueDesc();
		// 获取颜色配置信息
		List<PmFeaturValue> colorNumList = pmFeaturValueDao.getFeaturValueByType("vehicleColor", colorNum);
		if (colorNumList.size() < 1) {
			result.setSuccess(false);
			result.setMessage("无法获取车漆颜色配置信息");
			return result;
		}
		color = colorNumList.get(0).getFeatueValueDesc();
		parameters.put("MODEL",model);
		parameters.put("VEHICLECOLOR", paintColor + color);
		result.setObject(parameters);

		return result;
	}

	@Override
	public ResultBean copyLoadList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		Integer loadingListHeadId=Integer.parseInt(map.get("loadingListHeadId").toString());
		String headInfo =map.get("headInfo").toString();
		String configType =map.get("configType").toString();
		String partNoVersion = map.get("partNoVersion").toString();
		List<PrBasLoadingList> loadingListHead = listDao.getLoadingListHead(partNoVersion, configType);
		if(loadingListHead!=null && loadingListHead.size()>0) {
			result.setSuccess(false);
			result.setMessage("已存在该配置信息！");
			return result;
		}
		
		PrBasLoadingList prBasLoadingList = new PrBasLoadingList();
		prBasLoadingList.setCreate_time(new Date());
		prBasLoadingList.setCreate_user(SpringWebUtils.getRequestUser());
		prBasLoadingList.setConfigType(configType);
		prBasLoadingList.setHeadInfo(headInfo);
		prBasLoadingList.setPartNoVersion(partNoVersion);
		//新增装车单头信息
		listDao.addLoadingListHead(prBasLoadingList);
		//通过装车单头ID获取子项值信息
		List<PrBasLoadingList> loadingList = listDao.getLoadingList(loadingListHeadId);
		if(loadingList!=null && loadingList.size()>0) {
			for(int i=0;i<loadingList.size();i++) {
				prBasLoadingList.setPartNo(loadingList.get(i).getPartNo());
				prBasLoadingList.setPartDesc(loadingList.get(i).getPartDesc());
				prBasLoadingList.setSerialNum(loadingList.get(i).getSerialNum());
				listDao.addLoadingList(prBasLoadingList);
			}
		}
		
		return result;
	}

	@Override
	public ResultBean addLoadingList(List<PrBasLoadingList> list,Integer id) {
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		PrBasLoadingList prBasLoadingList = new PrBasLoadingList();
		prBasLoadingList.setCreate_time(new Date());
		prBasLoadingList.setCreate_user(SpringWebUtils.getRequestUser());
		prBasLoadingList.setLoadingListHeadId(id);
		if(list!=null &&list.size()>0&& id!=null) {
			for(int i=0;i<list.size();i++) {
				prBasLoadingList.setPartNo(list.get(i).getPartNo());
				prBasLoadingList.setPartDesc(list.get(i).getPartNameC());
				listDao.addLoadingList(prBasLoadingList);
			}
		}else {
			result.setSuccess(false);
			result.setMessage("数据异常");
			return result;
		}
		return result;
	}

	@Override
	public List<PrBasLoadingList> getPartInfo(PrBasLoadingList enti) {
		List<PrBasLoadingList> list = listDao.getPartInfo(enti);
		return list;
	}

	@Override
	public ResultBean addLoadListHead(PrBasLoadingList enti) {
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		List<PrBasLoadingList> checkLoadingList = listDao.checkLoadingListHead(enti);
		if(checkLoadingList!=null && checkLoadingList.size()>0) {
			result.setSuccess(false);
			result.setMessage("存在相同配置");
			return result;
		}
		enti.setCreate_time(new Date());
		enti.setCreate_user(SpringWebUtils.getRequestUser());
		listDao.addLoadingListHead(enti);
		return result;
	}

	@Override
	public void deleteLoadingListHead(PrBasLoadingList enti) {
		
		Integer loadingListHeadId = enti.getLoadingListHeadId();
		listDao.deleteLoadingListHead(loadingListHeadId);
		listDao.deleteLoadingListByHeadId(loadingListHeadId);
	}

	@Override
	public ResultBean updateLoadingList(PrBasLoadingList enti) {
		// TODO Auto-generated method stub
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		List<PrBasLoadingList> list = listDao.checkPrintSerial(enti);
		if(list!=null && list.size()>0) {
			result.setSuccess(false);
			result.setMessage("该配置打印序号已存在");
			return result;
		}
		listDao.updateLoadingList(enti);
		return result;
	}
//装车单预览
	@SuppressWarnings("unlikely-arg-type")
	@Override
	public void loadingListPreView(PrBasLoadingList enti,HttpServletResponse response) {
		// TODO Auto-generated method stub
//		Map<String,Object> parameters = new HashMap<String,Object>(); 
		String templateName = enti.getTemplateName();
		String configType = enti.getConfigType();
		String partNoVersion = enti.getPartNoVersion();
		String headInfo = enti.getHeadInfo();
		String vinOrSelf = enti.getVin();
		List<PrBasLoadingList> reportList=null;
		//模板文件地址
		String filePath = "jrxml/"+templateName+".jasper";
		
		ResultBean resultBean = getPrintParams(vinOrSelf,configType,partNoVersion);		
		@SuppressWarnings("unchecked")
		Map<String, Object> parameters = (Map<String, Object>) resultBean.getObject();
		
		SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
		SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");
		Date de = new Date();
		String time = df.format(de);
		String date = dt.format(de);
		parameters.put("header",headInfo);
		
		parameters.put("date",date);
		parameters.put("time", time);
		if(configType.equals("AL_TCFNS")){
			
			//获取总装配置的整车流水号信息
			List<PmSerialnumber> serialnumberConfigList = pmSerialnumberDao.getPmSerialnumberConfigInfo("ZZ");
			if(serialnumberConfigList!=null && serialnumberConfigList.size()>0) {
				int serialnumber= serialnumberConfigList.get(0).getSerial_number();
				StringBuffer bfBufferProNumber=new StringBuffer(String.valueOf(serialnumber));
				bfBufferProNumber.reverse();
				int size=5-bfBufferProNumber.length();
				for(int i=0;i<size;i++) {
					bfBufferProNumber.append("0");
				}
				bfBufferProNumber.reverse();
				Date d = new Date();
				SimpleDateFormat year = new SimpleDateFormat("yyyy");
				String yearCode= year.format(d).substring(year.format(d).length()-2, year.format(d).length());
				//生成装车单流水号
				String zzSerialnumber="ZZ"+yearCode+bfBufferProNumber;
				parameters.put("serial_number", zzSerialnumber); // 流水号
			}
		}else {

			//获取总装配置的驾驶室流水号信息
			List<PmSerialnumber> serialnumberConfigList1 = pmSerialnumberDao.getPmCabSerialnumberConfigInfo("ZZ");
			if(serialnumberConfigList1!=null && serialnumberConfigList1.size()>0) {
				int serialnumber= serialnumberConfigList1.get(0).getSerial_number();
				StringBuffer bfBufferProNumber=new StringBuffer(String.valueOf(serialnumber));
				bfBufferProNumber.reverse();
				int size=5-bfBufferProNumber.length();
				for(int i=0;i<size;i++) {
					bfBufferProNumber.append("0");
				}
				bfBufferProNumber.reverse();
				Date d = new Date();
				SimpleDateFormat year = new SimpleDateFormat("yyyy");
				String yearCode= year.format(d).substring(year.format(d).length()-2, year.format(d).length());
				//生成装车单流水号
				String zzSerialnumber="ZZ"+yearCode+bfBufferProNumber;
				parameters.put("serial_number", zzSerialnumber); // 流水号
			}

		}
		if(vinOrSelf!=null && !"".equals(vinOrSelf)) {
			parameters.put("VIN",vinOrSelf);
			List<PrBasLoadingList> reportList1 = listDao.getspecialRequire(enti.getVin()); 
			if(reportList1!=null&&reportList1.size()>0) {
				if(reportList1.get(0)!=null &&!"".equals(reportList1.get(0))) {
					parameters.put("parameter171",reportList1.get(0).getSpecialRequire());
				}
			
			}
			ResultBean resultModelColor = getVehicleModelColorByVin(vinOrSelf);
			if(resultModelColor.success) {
				Map<?, ?> mapModelColor=(Map<?, ?>) resultModelColor.object; 
				parameters.put("vehcile_type", mapModelColor.get("MODEL")); // 车型
				parameters.put("vehcile_color", mapModelColor.get("VEHICLECOLOR"));// 颜色
			}
			
		}		
		//填充参数，ireport中通过$P{key_name}获取		

		PrintCardUtil<PrBasLoadingList> util = new PrintCardUtil<>(reportList);
		//util.iReportWebPrint(parameters, filePath);
		util.iReportWebPrintResponse(parameters, filePath, response);

	}
	
	
	//获取打印参数
	public ResultBean getPrintParams(String vinOrSelf,String configType,String partNoVersion){
		
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		//通过vin或者自编号获取特殊要求
		Map<String, Object> parameters = new HashMap<String, Object>();
		List<PrBasLoadingList> getspecialRequireList = listDao.getspecialRequire(vinOrSelf); 
		if(getspecialRequireList!=null && getspecialRequireList.size()>0) {
			if(getspecialRequireList.get(0)!=null) {
				parameters.put("parameter171", getspecialRequireList.get(0).getSpecialRequire());
			}					
		}
		//通过成品物料号和配置类型获取装车单配置内容
		List<PrBasLoadingList> listLoading = listDao.getLoadingListByConfigType(configType, partNoVersion);
		if (listLoading == null || listLoading.size() < 1) {
			result.setSuccess(false);
			result.setMessage("无法获取装车单配置信息");
			result.setObject(parameters);
			return result;
		}
		parameters.put("header", listLoading.get(0).getHeadInfo());
		for(int i=0;i<listLoading.size();i++) {
			switch (listLoading.get(i).getSerialNum()) {
			case "1":
				parameters.put("parameter11", listLoading.get(i).getPartDesc());
				parameters.put("parameter21", listLoading.get(i).getPartNo());
				break;
			case "2":
				parameters.put("parameter12", listLoading.get(i).getPartDesc());
				parameters.put("parameter22", listLoading.get(i).getPartNo());
				break;
			case "3":
				parameters.put("parameter13", listLoading.get(i).getPartDesc());
				parameters.put("parameter23", listLoading.get(i).getPartNo());
				break;
			case "4":
				parameters.put("parameter14", listLoading.get(i).getPartDesc());
				parameters.put("parameter24", listLoading.get(i).getPartNo());
				break;
			case "5":
				parameters.put("parameter31", listLoading.get(i).getPartDesc());
				parameters.put("parameter41", listLoading.get(i).getPartNo());
				break;
			case "6":
				parameters.put("parameter32", listLoading.get(i).getPartDesc());
				parameters.put("parameter42", listLoading.get(i).getPartNo());
				break;
			case "7":
				parameters.put("parameter33", listLoading.get(i).getPartDesc());
				parameters.put("parameter43", listLoading.get(i).getPartNo());
				break;
			case "8":
				parameters.put("parameter34", listLoading.get(i).getPartDesc());
				parameters.put("parameter44", listLoading.get(i).getPartNo());
				break;
			case "9":
				parameters.put("parameter51", listLoading.get(i).getPartDesc());
				parameters.put("parameter61", listLoading.get(i).getPartNo());
				break;
			case "10":
				parameters.put("parameter52", listLoading.get(i).getPartDesc());
				parameters.put("parameter62", listLoading.get(i).getPartNo());
				break;
			case "11":
				parameters.put("parameter53", listLoading.get(i).getPartDesc());
				parameters.put("parameter63", listLoading.get(i).getPartNo());
				break;
			case "12":
				parameters.put("parameter54", listLoading.get(i).getPartDesc());
				parameters.put("parameter64", listLoading.get(i).getPartNo());
				break;
			case "13":
				parameters.put("parameter71", listLoading.get(i).getPartDesc());
				parameters.put("parameter81", listLoading.get(i).getPartNo());
				break;
			case "14":
				parameters.put("parameter72", listLoading.get(i).getPartDesc());
				parameters.put("parameter82", listLoading.get(i).getPartNo());
				break;
			case "15":
				parameters.put("parameter73", listLoading.get(i).getPartDesc());
				parameters.put("parameter83", listLoading.get(i).getPartNo());
				break;
			case "16":
				parameters.put("parameter74", listLoading.get(i).getPartDesc());
				parameters.put("parameter84", listLoading.get(i).getPartNo());
				break;
			case "17":
				parameters.put("parameter91", listLoading.get(i).getPartDesc());
				parameters.put("parameter101", listLoading.get(i).getPartNo());
				break;
			case "18":
				parameters.put("parameter92", listLoading.get(i).getPartDesc());
				parameters.put("parameter102", listLoading.get(i).getPartNo());
				break;
			case "19":
				parameters.put("parameter93", listLoading.get(i).getPartDesc());
				parameters.put("parameter103", listLoading.get(i).getPartNo());
				break;
			case "20":
				parameters.put("parameter94", listLoading.get(i).getPartDesc());
				parameters.put("parameter104", listLoading.get(i).getPartNo());
				break;
			case "21":
				parameters.put("parameter111", listLoading.get(i).getPartDesc());
				parameters.put("parameter121", listLoading.get(i).getPartNo());
				break;
			case "22":
				parameters.put("parameter112", listLoading.get(i).getPartDesc());
				parameters.put("parameter122", listLoading.get(i).getPartNo());
				break;
			case "23":
				parameters.put("parameter113", listLoading.get(i).getPartDesc());
				parameters.put("parameter123", listLoading.get(i).getPartNo());
				break;
			case "24":
				parameters.put("parameter114", listLoading.get(i).getPartDesc());
				parameters.put("parameter124", listLoading.get(i).getPartNo());
				break;
			case "25":
				parameters.put("parameter131", listLoading.get(i).getPartDesc());
				parameters.put("parameter141", listLoading.get(i).getPartNo());
				break;
			case "26":
				parameters.put("parameter132", listLoading.get(i).getPartDesc());
				parameters.put("parameter142", listLoading.get(i).getPartNo());
				break;
			case "27":
				parameters.put("parameter133", listLoading.get(i).getPartDesc());
				parameters.put("parameter143", listLoading.get(i).getPartNo());
				break;
			case "28":
				parameters.put("parameter134", listLoading.get(i).getPartDesc());
				parameters.put("parameter144", listLoading.get(i).getPartNo());
				break;
			case "29":
				parameters.put("parameter151", listLoading.get(i).getPartDesc());
				parameters.put("parameter161", listLoading.get(i).getPartNo());
				break;
			case "30":
				parameters.put("parameter152", listLoading.get(i).getPartDesc());
				parameters.put("parameter162", listLoading.get(i).getPartNo());
				break;
			case "31":
				parameters.put("parameter153", listLoading.get(i).getPartDesc());
				parameters.put("parameter163", listLoading.get(i).getPartNo());
				break;
			case "32":
				parameters.put("parameter154", listLoading.get(i).getPartDesc());
				parameters.put("parameter164", listLoading.get(i).getPartNo());
				break;
			default:
				break;
			}
		}
		result.setObject(parameters);
		return result;
		
	}
	//通过vin获取车型和颜色
		public ResultBean getVehicleModelColorByVin(String vin) {
			// TODO Auto-generated method stub
			ResultBean result  = new ResultBean(true,"'");
			result.setSuccess(true);
			
			List<TwBasLot> lotList = lotDao.selectTwBasLotByVinOrSelf(vin);
			if(lotList==null ||lotList.size()<1) {
				result.setSuccess(false);
				result.setMessage("无法获取车辆信息");
				return result;
			}
			TwBasLot basLot = lotList.get(0);
			String partNoVersion=basLot.getPartNoVersion();
			
			if(partNoVersion==null ||  "".equals(partNoVersion)) {
				result.setSuccess(false);
				result.setMessage("无法获取物料号信息");
				return result;
			}
			String paintColorNum =partNoVersion.substring(partNoVersion.length()-9, partNoVersion.length()-8);
			String colorNum =partNoVersion.substring(partNoVersion.length()-8, partNoVersion.length()-6);
			String model="";
			String paintColor="";
			String color="";
			Map<String,Object> parameters = new HashMap<String,Object>(); 
			//获取车型
			List<PmPartModelAndVinRule> listVinRuleInfo = vinRuleDao.getVinRuleInfo(partNoVersion);
			if(listVinRuleInfo==null || listVinRuleInfo.size()<1 ) {
				result.setSuccess(false);
				result.setMessage("无法获取车型配置信息");
				return result;
			}
			model = listVinRuleInfo.get(0).getModel();
			//获取车漆配置信息
			List<PmFeaturValue> paintColorNumList  = pmFeaturValueDao.getFeaturValueByType("vehiclePaintType",paintColorNum);
			if(paintColorNumList.size()<1) {
				result.setSuccess(false);
				result.setMessage("无法获取车漆属性配置信息");
				return result;
			}
			paintColor=paintColorNumList.get(0).getFeatueValueDesc();
			//获取颜色配置信息
			List<PmFeaturValue> colorNumList  = pmFeaturValueDao.getFeaturValueByType("vehicleColor",colorNum);
			if(colorNumList.size()<1) {
				result.setSuccess(false);
				result.setMessage("无法获取车漆颜色配置信息");
				return result;
			}
			color=colorNumList.get(0).getFeatueValueDesc();
			parameters.put("MODEL",model);
			parameters.put("VEHICLECOLOR", paintColor+color);
			parameters.put("STATUSNUM", partNoVersion);
			result.setObject(parameters);
			
			
			
			return result;
		}
}
